home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / extras / programm / gemfsc20 / gemfsc20.lzh / GEMFUNCS / FRMNLDSU.C < prev    next >
C/C++ Source or Header  |  1993-02-01  |  5KB  |  192 lines

  1. /**************************************************************************
  2.  * FRMNLDSU.C - Some service routines used by frm_nl and frm_ds functions.
  3.  *************************************************************************/
  4.  
  5. #include "gemfintl.h"
  6. #include <string.h>
  7.  
  8. #define JUSTIFY_LEFT   0
  9. #define JUSTIFY_CENTER 2
  10.  
  11. /*-------------------------------------------------------------------------
  12.  *
  13.  *-----------------------------------------------------------------------*/
  14.  
  15. static TEDINFO GFAR local_tedinfos[] = {
  16.   {NULL, NULL, NULL, 3, 6, 0, 0x11F0, 0,  0,   1,    1},
  17.   {NULL, NULL, NULL, 3, 6, 0, 0x11F0, 0,  0,   1,    1},
  18.   {NULL, NULL, NULL, 3, 6, 0, 0x11F0, 0,  0,   1,    1},
  19.   {NULL, NULL, NULL, 3, 6, 0, 0x11F0, 0,  0,   1,    1},
  20.   {NULL, NULL, NULL, 3, 6, 0, 0x11F0, 0,  0,   1,    1},
  21.   {NULL, NULL, NULL, 3, 6, 0, 0x11F0, 0,  0,   1,    1},
  22.   {NULL, NULL, NULL, 3, 6, 0, 0x11F0, 0,  0,   1,    1},
  23.   {NULL, NULL, NULL, 3, 6, 0, 0x11F0, 0,  0,   1,    1},
  24.   {NULL, NULL, NULL, 3, 6, 0, 0x11F0, 0,  0,   1,    1},
  25.   {NULL, NULL, NULL, 3, 6, 0, 0x11F0, 0,  0,   1,    1},
  26.   {NULL, NULL, NULL, 3, 6, 0, 0x11F0, 0,  0,   1,    1},
  27.   {NULL, NULL, NULL, 3, 6, 0, 0x11F0, 0,  0,   1,    1},
  28.   {NULL, NULL, NULL, 3, 6, 0, 0x11F0, 0,  0,   1,    1},
  29.   {NULL, NULL, NULL, 3, 6, 0, 0x11F0, 0,  0,   1,    1},
  30.   {NULL, NULL, NULL, 3, 6, 0, 0x11F0, 0,  0,   1,    1},
  31.   {NULL, NULL, NULL, 3, 6, 0, 0x11F0, 0,  0,   1,    1},
  32.   {NULL, NULL, NULL, 3, 6, 0, 0x11F0, 0,  0,   1,    1},
  33.   {NULL, NULL, NULL, 3, 6, 0, 0x11F0, 0,  0,   1,    1},
  34.   {NULL, NULL, NULL, 3, 6, 0, 0x11F0, 0,  0,   1,    1},
  35.   {NULL, NULL, NULL, 3, 6, 0, 0x11F0, 0,  0,   1,    1}
  36. };
  37.  
  38. typedef struct ___size_sanity_check___ {
  39.     char x[FRM_DSMAXSTRINGS == Array_els(local_tedinfos)];
  40. } ___size_sanity_check___;
  41.  
  42. /*-------------------------------------------------------------------------
  43.  * set width of an object and all its children.
  44.  *-----------------------------------------------------------------------*/
  45.  
  46. void _FrmTrWidths(ptree, parent, width)
  47.     register OBJECT *ptree;
  48.     register short      parent;
  49.     register short      width;
  50. {
  51.     register short      curobj;
  52.  
  53.     ptree[parent].ob_width = width;
  54.     curobj = ptree[parent].ob_head;
  55.  
  56.     while (curobj != parent && curobj >= ROOT) {
  57.         ptree[curobj].ob_width = width;
  58.         curobj = ptree[curobj].ob_next;
  59.     }
  60. }
  61.  
  62. /*-------------------------------------------------------------------------
  63.  * attach string pointers from array to tedinfo pointers,
  64.  * attach tedinfos to tree objects.
  65.  * if the objects pointed to by pobj are not G_xTEXT objects, it
  66.  * attaches the strings directly to the objects and doesn't touch
  67.  * the tedinfo array at all.
  68.  *-----------------------------------------------------------------------*/
  69.  
  70. short _FrmDS2Obj(ppstr, pobj, pted, pwidth, maxobj)
  71.     register char     **ppstr;
  72.     register OBJECT  *pobj;
  73.     register TEDINFO *pted;
  74.     short               *pwidth;
  75.     short               maxobj;
  76. {
  77.     char             *pstr;
  78.     register short      len;
  79.     register short       counter;
  80.     register short       linecount = 0;
  81.     register short       width     = *pwidth;
  82.     short               sumwidth  = FALSE;
  83.     short               center_it;
  84.  
  85.     if (width == -1) {
  86.         sumwidth = TRUE;
  87.         width     = 0;
  88.     }
  89.  
  90.     if (pted == NULL) {
  91.         pted = local_tedinfos;
  92.     }
  93.  
  94.     for (counter = 0; counter < maxobj; ++counter) {
  95.         pstr = *ppstr;
  96.         if (pstr == NULL) {
  97.             pobj->ob_flags |= HIDETREE;
  98.         } else {
  99.             pobj->ob_flags &= ~HIDETREE;
  100.             if (*pstr == 0x7F) {
  101.                 center_it = TRUE;
  102.                 ++pstr;
  103.             } else {
  104.                 center_it = FALSE;
  105.             }
  106.             len  = (short)strlen(pstr);
  107.             if (sumwidth) {
  108.                 width += len;
  109.             } else if (width < len) {
  110.                 width = len;
  111.             }
  112.             switch (pobj->ob_type & 0x00FF) {
  113.               case G_TEXT:
  114.               case G_BOXTEXT:
  115.               case G_FTEXT:
  116.               case G_FBOXTEXT:
  117.                 pobj->_Ob_spec     = (_Ob_spec_t)pted;
  118.                 pted->te_ptext    = pstr;
  119.                 pted->te_txtlen = len;
  120.                 pted->te_just    = (center_it) ? JUSTIFY_CENTER : JUSTIFY_LEFT;
  121.                 break;
  122.               default:
  123.                 pobj->_Ob_spec     = (_Ob_spec_t)pstr;
  124.                 break;
  125.             }
  126.             ++ppstr;
  127.             ++linecount;
  128.         }
  129.         ++pobj;
  130.         ++pted;
  131.     }
  132.  
  133.     *pwidth = width;
  134.     return linecount;
  135. }
  136.  
  137. /*-------------------------------------------------------------------------
  138.  * Go put \n chars back in all the places where we changed them to \0.
  139.  *-----------------------------------------------------------------------*/
  140.  
  141. void _FrmNLPatch(patch_array)
  142.     register char  **patch_array;
  143. {
  144.     register char    *thepatch;
  145.  
  146.     while (NULL != (thepatch = *patch_array)) {
  147.         *thepatch = '\n';
  148.         ++patch_array;
  149.     }
  150. }
  151.  
  152. /*-------------------------------------------------------------------------
  153.  * Divide \n-delimited string into set of \0-terminated strings.
  154.  *-----------------------------------------------------------------------*/
  155.  
  156. void _FrmNL2DS(strings, pointer_array, patch_array, maxstrings)
  157.     register char     *strings;
  158.     register char    **pointer_array;
  159.     register char    **patch_array;
  160.     register short        maxstrings;
  161. {
  162.     register short        counter;
  163.     register char      c;
  164.  
  165.     for (counter = 0; *strings && counter < maxstrings; ++counter) {
  166.         *pointer_array = strings;
  167.         for (;;) {
  168.             c = *strings;
  169.             if (c == '\0' || c == '\n') {
  170.                 break;
  171.             }
  172.             ++strings;
  173.         }
  174.         if (c == '\n') {
  175.             if (patch_array) {
  176.                 *patch_array++ = strings;
  177.             }
  178.             *strings++ = '\0';
  179.         }
  180.         if (**pointer_array == '\0') {
  181.             *pointer_array = " ";
  182.         }
  183.         ++pointer_array;
  184.     }
  185.     *pointer_array = NULL;
  186.     if (patch_array) {
  187.         *patch_array   = NULL;
  188.     }
  189. }
  190.  
  191.  
  192.